import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { VbenFormSchema } from '#/adapter/form';
import type { DictApi, SubjectApi } from '#/api';

import { reactive } from 'vue';

import { DictResp } from '#/api';

const mes_dvsubject_type = reactive<DictApi.SelectOption[]>([]);
/**
 * 获取下拉框数据，以及回填其他隐藏数据
 */

DictResp(['mes_dvsubject_type']).then((res) => {
  // 将两个数组合并
  if (res.mes_dvsubject_type) {
    mes_dvsubject_type.push(...res.mes_dvsubject_type);
  }
});
export function useChildSearchForm(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入项目编码',
        class: 'mr-5',
      },
      fieldName: 'subjectCode',
      label: '项目编码',
      labelClass: 'text-[#606266] font-bold',
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入项目名称',
      },
      fieldName: 'subjectName',
      label: '项目名称',
      labelClass: '  text-[#606266] font-bold',
    },
  ];
}

/**
 * 获取表格列配置
 */
export function useChildSubjectColumns(): VxeTableGridOptions<SubjectApi.CheckRow>['columns'] {
  return [
    {
      field: 'checkbox',
      fixed: 'left',
      type: 'checkbox',
      width: 50,
    },
    {
      field: 'subjectCode',
      title: '项目编码',
    },
    {
      field: 'subjectType',
      title: '设备类型',
      formatter: ({ cellValue }) => {
        const item = mes_dvsubject_type.find(
          (item) => item.value === cellValue,
        );
        return item?.label || '无';
      },
    },
    {
      field: 'subjectContent',
      title: '项目内容',
    },
    {
      field: 'subjectStandard',
      title: '标准',
    },
    {
      field: 'enableFlag',
      title: '是否启用',
      cellRender: { name: 'CellTag' },
    },

    {
      title: '备注',
      field: 'remark',
    },
  ];
}

/**
 * tabs Subject 表格列配置
 * @returns 表格列配置
 */
export function useSubjectTabColumns(): VxeTableGridOptions<SubjectApi.CheckRow>['columns'] {
  return [
    {
      field: 'checkbox',
      fixed: 'left',
      type: 'checkbox',
      width: 50,
    },
    {
      field: 'subjectName',
      title: '项目名称',
    },
    {
      field: 'subjectContent',
      title: '项目内容',
    },
    {
      title: '标准',
      field: 'subjectStandard',
    },
    {
      field: 'action',
      title: '操作',
      fixed: 'right',
      align: 'center',
      slots: { default: 'action' },
    },
  ];
}
